/** 工作存储
 * @ 标  识: hchhIOT
 * @ 作  者: 阿拉丁矿工 黄传鸿 <hchhyzc@foxmail.com>
 */
/* ================================================================================================ */
//                                ★ 引入
/* ================================================================================================ */
import { defineStore } from "pinia";

/**———————————————————————————————————————————————————————————————————————————————————————————————— */
//                                ★ 存储
/**———————————————————————————————————————————————————————————————————————————————————————————————— */
export const useWorkStore = defineStore({
  id: "useWorkStore",
  /* ================================================================================================ */
  //                               ★ state
  /* ================================================================================================ */
  state: (): any => {
    return {
      /** 工作模式:1-设计模式;2-运行模式  */
      workModel: 1,
      /** 动画获取值 */
      anGetVal: 0,
      /** 动画判断值 */
      anJudgeVal: 0,
      /** 执行缓存  */
      executeBuffer: [],
      /** 页面数据  */
      pageData: [],
      /** 通道 */
      channels: [
        /** PLC */
        {
          label: "PLC",
          key: "PLC",
          checkboxDisabled: true,
          isLeaf: false,
          active: false,
          category: 0,
          children: [
            /** AB PLC */
            {
              label: "罗克韦尔PLC",
              key: "AB_PLC",
              checkboxDisabled: true,
              isLeaf: false,
              active: false,
              category: 1,
              children: [
                {
                  label: 'ControlLogix型PLC',
                  key: 'AB_PLC_01',
                  type: 'AB_PLC_Control',
                  isLeaf: true,
                  active: false,
                  category: 2,
                  ip_addr: "192.168.0.3",
                  cpu_slot: 0,
                },
                {
                  label: 'CompactLogix型PLC',
                  key: 'AB_PLC_02',
                  type: 'AB_PLC_Compact',
                  isLeaf: true,
                  active: true,
                  category: 2,
                  ip_addr: "192.168.0.3",
                  cpu_slot: 1,

                },
                {
                  label: 'Micro8xx型PLC',
                  key: 'AB_PLC_03',
                  type: 'AB_PLC_Micro',
                  isLeaf: true,
                  active: false,
                  category: 2,
                  ip_addr: "192.168.0.3",
                  cpu_slot: 2,
                }
              ],
            },
            /** 西门子PLC */
            {
              label: "西门子PLC",
              key: "Siemens_PLC",
              isLeaf: true,
              active: false,
              category: 1,
            },
            /** 三菱PLC */
            {
              label: "三菱PLC",
              key: "Mitsubishi_PLC",
              isLeaf: true,
              active: false,
              category: 1,
            },
          ],
        },
        /** 变频器 */
        {
          label: "变频器",
          key: "Converter",
          isLeaf: false,
          checkboxDisabled: true,
          active: false,
          category: 0,
          children: [
            /** ModBus TCP */
            {
              label: "三肯VM05",
              key: "Samco-VM05",
              isLeaf: true,
              active: false,
              category: 1,
            },
          ],
        },
        /** 通用串口 */
        {
          label: "通用串口",
          key: "Serial",
          isLeaf: false,
          checkboxDisabled: true,
          active: false,
          category: 0,
          children: [
            /** CAN */
            {
              label: "CAN",
              key: "Serial_CAN",
              isLeaf: true,
              active: false
            },
            /** ModBus RTU */
            {
              label: "ModBus RTU",
              key: "Serial_ModBusRTU",
              isLeaf: true,
              active: false
            },
            /** ModBus TCP */
            {
              label: "ModBus TCP",
              key: "Serial_ModBusTCP",
              isLeaf: true
            },
          ],
        },
        /** 数据库 */
        {
          label: "数据库",
          key: "TCP_IP_Database",
          isLeaf: false,
          checkboxDisabled: true,
          active: false,
          category: 0,
          children: [
            {
              label: "MySQL",
              key: "MySQL",
              isLeaf: true,
              active: false
            },
            {
              label: "MongoDB",
              key: "TCP_IP_Database_MongoDB",
              isLeaf: true,
              active: false
            },
          ],
        },
        /** OPC服务 */
        {
          label: "OPC服务",
          key: "OPC",
          isLeaf: true,
          active: false,
          category: 1,
        },
        /** MQTT服务 */
        {
          label: "MQTT服务",
          key: "MQTT",
          isLeaf: true,
          active: false,
          category: 1,
        },
        /** WiFi */
        {
          label: "WiFi",
          key: "WiFi",
          isLeaf: true,
          active: false,
          category: 1,
        },
        /** 蓝牙 */
        {
          label: "蓝牙",
          key: "Bluetooth",
          isLeaf: true,
          active: false,
          category: 1,
        },
        /** Lora */
        {
          label: "Lora",
          key: "Lora",
          isLeaf: true,
          active: false,
          category: 1,
        },

      ],
      /** 设备数据 */
      equipData: [
        {
          equipDataId: "E01",         // 设备id;
          equipDataDescr: "水泵开",     // 设备名称;
          equipDataLabel: "pump1Open",// 标签;
          equipDataType: 0,           // 设备数据类型:0_布尔;1_8位;2_16位;3_16位;4_32位;5_字符;
          equipDataRW: 0,             // 读写选项:0_读;1_写;
          channelId: "none",          // 通道Id;
          equipDataVal: '10',         // 变量值;
        }
      ],
      /** 图元数据  */
      pelData: [
        {
          pelDataDescr: "描述",  // 图元数据描述;
          pelDataLabel: "pump1",// 图元数据标签;
          pelDataType: 1,       // 类型选项:0-JSON数据;1-单行文本;2-颜色; 
          pelDataVal: '10',     // 图元数据值;
          pelDataId: "S01",     // 图元数据id;
          equipDataId: "none",   // 设备id;
        },
      ],
      /** 图元  */
      pels: [],
      /** 导航列表  */
      navigationList: [],
      /** 发送缓存  */
      sendBuffer:[]
    }
  },
  /* ================================================================================================ */
  //                               ★ getters
  /* ================================================================================================ */
  getters: {},

  /* ================================================================================================ */
  //                               ★ actions
  /* ================================================================================================ */
  actions: {

  },
});
